<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>Création/Modification DJ</title>
        <meta name="keywords" content="" />
        <meta name="description" content="" />
        <link rel="stylesheet" type="text/css" href="../default.css" />
        <script type="text/javascript" src="../jquery.js"></script>
        <script type="text/javascript" src="../scripts.js"></script>

    </head>
    <body>
        <div id="upbg"></div>
        <div id="outer">

            <?php
            include '../headerAdmin.php';
            include '../menuAdmin.php';
            ?>
            <div id="content">

                <?php
                include '../connectBDD.php';
                if (isset($_GET['id_dj'])) {
                    $id_dj = $_GET['id_dj'];
                    if (isset($_POST["creationDJ"]) && $_POST["creationDJ"] == "ok") {
                        //On test si tout les champs ont bien été remplis.
                        if (!empty($_POST["nomDJ"]) && !empty($_POST["descriptionDJ"])) {
                            $query = " update dj set 
                                pseudo_dj = '" . $_POST['nomDJ'] . "',
                                description_dj = '" . addslashes($_POST['descriptionDJ']). "',
                                site_dj = '" . $_POST['siteDJ'] . "' 
                                where id_dj = ".$id_dj;
                            //requete qui insert l'ensemble des champs dans la base de données
                            mysql_query($query) or die(mysql_error());
                            echo "<div style='color:green;'>Modification du DJ reussie</div>";
                        }else
                            echo "<div style='color:red;'>Veuillez renseigner tous les champs.</div>";
                    }
                        $query = "select * from dj where id_dj=" . $_GET['id_dj'];
                        $result = mysql_query($query);
                        if (mysql_num_rows($result) > 0) {
                            $row = mysql_fetch_assoc($result);
                            $pseudo = $row['pseudo_dj'];
                            $description = $row['description_dj'];
                            $site = $row['site_dj'];
                        }
                    
                } else if (isset($_POST["creationDJ"]) && $_POST["creationDJ"] == "ok") {
                    //On test si tout les champs ont bien été remplis.
                    if (!empty($_POST["nomDJ"]) &&
                            !empty($_POST["descriptionDJ"])) {
                        $query = " insert into dj (pseudo_dj,description_dj, site_dj) 
                                values ('" . $_POST['nomDJ'] . "', '" . $_POST['descriptionDJ'] . "',
                                '" . $_POST['siteDJ'] . "')";
                        //requete qui insert l'ensemble des champs dans la base de données
                        mysql_query($query) or die(mysql_error());
                        echo "<div style='color:green;'>Création du DJ reussie</div>";
                    }else
                        echo "<div style='color:red;'>Veuillez renseigner tous les champs.</div>";
                }
                ?>
                <div id='blockInscription'>
                    <div class='sousTitreInfoInscription'>Création/Modification d'un DJ</div>
                    <form action="creationDJ.php<?php if (isset($id_dj)) {
                    echo '?id_dj='.$id_dj;
                } ?>" method="post"><p>
                            <label for="nomDJ">Pseudo :</label><input type="text" name="nomDJ" value="<?php if (isset($id_dj)) {
                    echo $pseudo;
                } ?>"/><br />
                            <label for='siteDJ'>Site du DJ : </label><input type='text' name='siteDJ' value='<?php if (isset($id_dj)) {
                    echo $site;
                } ?>' /><br />
                            <label for='descriptionDJ'>Description : </label><textarea rows="6" cols="40" name="descriptionDJ" /><?php if (isset($id_dj)) {
                    echo $description;
                } ?></textarea><br />
                            <label for="cache"> </label>	<input type="hidden" name="creationDJ" value="ok"/>
                            <div>
                                <input type="submit" value="Enregistrer" name="bouton" />
                            </div>
                        </p></form>

                </div>

<?php
include '../footer.php';
?>

                </body>
                </html>

